package com.warm.androidstudy.utils;

import java.net.URLDecoder;
import java.net.URLEncoder;

public class URLEncodeUtils {

    //Encode转换
    public static String toEncode(String paramString) {

        if (paramString == null || paramString.equals("")) {
            LogUtil.e("toURLEncoded error:" + paramString);
            return "";
        }

        try {
            String str = new String(paramString.getBytes(), "UTF-8");
            str = URLEncoder.encode(str, "UTF-8");
            return str;
        } catch (Exception e) {
            LogUtil.e("toURLEncoded error:" + paramString);
        }

        return "";
    }


    //解析
    public static String toDecode(String paramString) {
        if (paramString == null || paramString.equals("")) {
            LogUtil.e("toURLDecoded error:" + paramString);
            return "";
        }

        try {
            String str = new String(paramString.getBytes(), "UTF-8");
            str = URLDecoder.decode(str, "UTF-8");
            return str;
        } catch (Exception e) {
            LogUtil.e("toURLDecoded error:" + paramString);
        }

        return "";
    }
}
